function submit(){
    var name = $('#name').val();
    var age = $('#age').val();
    var phone = $('#phone').val();
    var birthday = $('#birthday').val();
    var address = $('#address').val();
    var guardian = $('#guardian').val();
    var guardianPhone = $('#guardianPhone').val();
    var health = $('input[name=health]:checked').val();
    var healthCondition = $('#healthCondition').val();
    var familyStatus = $('input[name=familyStatus]:checked').val();
    var reg_name = /^[\u4e00-\u9fa5]{2,10}$/;
    var protocol = window.location.protocol;
    var host = window.location.host;
    if (name == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "姓名不能为空！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }else if (!reg_name.test(name)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "姓名只能由2-10个中文字符组成！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (age == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "年龄不能为空！",
            yes:function (index){
                $('#age').focus();
                layer.close(index);
            }
        });
        return "";
    }
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    if (!reg_tel.test(phone)) {
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "请正确填写手机号码！",
            yes:function (index){
                $('#phone').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (birthday == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "生日不能为空！",
            yes:function (index){
                $('#birthday').focus();
                layer.close(index);
            }
        });
        return "";
    }

    if (address == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "住址不能为空！",
            yes:function (index){
                $('#address').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (familyStatus !=0 && familyStatus !=1 && familyStatus !=2){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "请选择家庭状况！",
            yes:function (index){
                layer.close(index);
            }
        });
        return "";
    }
    if (health !=0 && health !=1 && health !=2){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "请选择健康状况！",
            yes:function (index){
                layer.close(index);
            }
        });
        return "";
    }
    if (health == 1 &&healthCondition == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "健康状况一般必须填写具体情况！",
            yes:function (index){
                $('#guardianPhone').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (health == 2 &&healthCondition == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "健康状况较差必须填写具体情况！",
            yes:function (index){
                $('#guardianPhone').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (guardian == ""){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "监护人姓名不能为空！",
            yes:function (index){
                $('#guardian').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (!reg_name.test(guardian)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "监护人姓名只能由2-10个中文字符组成！",
            yes:function (index){
                $('#name').focus();
                layer.close(index);
            }
        });
        return "";
    }
    if (!reg_tel.test(guardianPhone)){
        layer.open({
            title: '提示信息',
            anim: 0,
            resize:false,//是否可以拉伸  默认true
            icon: 2,
            shadeClose: true,
            skin: 'layui-layer-molv',
            content: "请正确填写监护人手机号码！",
            yes:function (index){
                $('#guardianPhone').focus();
                layer.close(index);
            }
        });
        return "";
    }
    //检验生日和年龄是否匹配
    var strBirthday = birthday;
    var returnAge;
    var strBirthdayArr=strBirthday.split("-");
    var birthYear = strBirthdayArr[0];
    var birthMonth = strBirthdayArr[1];
    var birthDay = strBirthdayArr[2];
    d = new Date();
    var nowYear = d.getFullYear();
    var nowMonth = d.getMonth() + 1;
    var nowDay = d.getDate();
    if(nowYear == birthYear)
    {
        returnAge = 0;//同年 则为0岁
        if (age != returnAge){
            layer.open({
                title: '提示信息',
                anim: 0,
                resize:false,//是否可以拉伸  默认true
                icon: 2,
                shadeClose: true,
                skin: 'layui-layer-molv',
                content: "年龄与生日不匹配,请仔细核对！",
                yes:function (index){
                    $('#age').focus();
                    layer.close(index);
                }
            });
            return "";
        }
    }
    else
    {
        var ageDiff = nowYear - birthYear ; //年之差
        if(ageDiff > 0)
        {
            if(nowMonth == birthMonth)
            {
                var dayDiff = nowDay - birthDay;//日之差
                if(dayDiff < 0)
                {
                    returnAge = ageDiff - 1;
                    if (age != returnAge){
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: "年龄与生日不匹配,请仔细核对！",
                            yes:function (index){
                                $('#age').focus();
                                layer.close(index);
                            }
                        });
                        return "";
                    }
                }
                else
                {
                    returnAge = ageDiff ;
                    if (age != returnAge){
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: "年龄与生日不匹配,请仔细核对！",
                            yes:function (index){
                                $('#age').focus();
                                layer.close(index);
                            }
                        });
                        return "";
                    }
                }
            }
            else
            {
                var monthDiff = nowMonth - birthMonth;//月之差
                if(monthDiff < 0)
                {
                    returnAge = ageDiff - 1;
                    if (age != returnAge){
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: "年龄与生日不匹配,请仔细核对！",
                            yes:function (index){
                                $('#age').focus();
                                layer.close(index);
                            }
                        });
                        return "";
                    }
                }
                else
                {
                    returnAge = ageDiff ;
                    if (age != returnAge){
                        layer.open({
                            title: '提示信息',
                            anim: 0,
                            resize:false,//是否可以拉伸  默认true
                            icon: 2,
                            shadeClose: true,
                            skin: 'layui-layer-molv',
                            content: "年龄与生日不匹配,请仔细核对！",
                            yes:function (index){
                                $('#age').focus();
                                layer.close(index);
                            }
                        });
                        return "";
                    }
                }
            }
        }
        else
        {
            returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
            if (age != returnAge){
                layer.open({
                    title: '提示信息',
                    anim: 0,
                    resize:false,//是否可以拉伸  默认true
                    icon: 2,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    content: "出生日期输入错误,晚于今天！",
                    yes:function (index){
                        $('#age').focus();
                        layer.close(index);
                    }
                });
                return "";
            }
        }
    }

    $.ajax({
        type : 'POST',
        url : '/elderlyAdd',
        data : {name:name,age:age,phone:phone,birthday:birthday,address:address,
            guardian:guardian,guardianPhone:guardianPhone,healthCondition:healthCondition,health:health
        ,familyStatus:familyStatus},
        success:function (data) {

            if (data == "OK"){
                layer.open({
                title: '提示信息',
                anim: 0,
                resize:false,//是否可以拉伸  默认true
                icon: 1,
                shadeClose: true,
                skin: 'layui-layer-molv',
                content: data,
                yes:function (index){
                    window.location.href = protocol+"//"+host+"/elderlyList";
                    layer.close(index);
                }
            });
            }else {
                layer.open({
                    title: '提示信息',
                    anim: 0,
                    resize:false,//是否可以拉伸  默认true
                    icon: 2,
                    shadeClose: true,
                    skin: 'layui-layer-molv',
                    content: data
                });
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
}